﻿<UserControl x:Class="ScrumFactory.HelpDeskPlugin.HelpDesk"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"                          
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Helpers_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             
             xmlns:props="clr-namespace:ScrumFactory.HelpDeskPlugin.Properties"

             x:Name="thisView"
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"

             HorizontalAlignment="Stretch" 
           
             
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding RefreshCommand}" />
    </UserControl.InputBindings>


    <UserControl.Resources>

        <Style x:Key="TickectBorder" TargetType="Border">
            <Setter Property="Height" Value="60"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="Padding" Value="2,8,2,8"/>
            <Setter Property="Background" Value="{StaticResource DoneBacklogItemBackground}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Item.Status}" Value="0">
                    <Setter Property="Background" Value="{StaticResource ToDoBacklogItemBackground}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Item.Status}" Value="1">
                    <Setter Property="Background" Value="{StaticResource WorkingBacklogItemBackground}" />
                </DataTrigger>
            </Style.Triggers> 

        </Style>

        <Style x:Key="NewItemPanelAutoClose2" TargetType="Grid" >
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="Height" Value="0"/>
            <Setter Property="TextBlock.Foreground" Value="{StaticResource LabelBrush}" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="LostKeyboardFocus">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Height" To="0" Duration="00:00:00.3" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="GotKeyboardFocus">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Height" To="80" Duration="00:00:00.3" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <!--<EventTrigger RoutedEvent="GotFocus">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Height" To="65" Duration="00:00:00.3" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>-->
            </Style.Triggers>
        </Style>

    
    </UserControl.Resources>
    
    <SF_Helpers:PanelLayout 
            ShowCurrentProjectName="False"            
            SF_Helpers_Ext:SearchBoxExtension.SearchBox="{Binding ElementName=searchTextBox}"
            Title="{Binding PanelName}" Background="Transparent" BorderBrush="Transparent">

        <!-- TOOLBAR -->
        <SF_Helpers:PanelLayout.Toolbar>
            <Grid>            
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <ToolBar Grid.Row="0" HorizontalAlignment="Stretch">


                    <MenuItem Header="{x:Static props:Resources.New_ticket}" Focusable="False">
                        <MenuItem.Icon>
                            <Image Source="pack://application:,,,/ScrumFactory.HelpDeskPlugin;component/Images/help_desk.png" Width="32" Height="32" Stretch="Uniform"/>
                        </MenuItem.Icon>

                        <MenuItem.Style>
                            <Style BasedOn="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}" TargetType="MenuItem">
                                <Style.Triggers>
                                    <Trigger Property="MenuItem.IsPressed" Value="True">
                                        <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=addTextBox}"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>

                </ToolBar>


                <Grid x:Name="newItemPanel"
                            Grid.ColumnSpan="2" Grid.Row="1"
                            Style="{StaticResource NewItemPanelAutoClose2}">
                    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Stretch">
                        
                        <ComboBox
                            Focusable="False"
                            SelectedValue="{Binding NewTicketProject}"                        
                            Width="250"
                            BorderBrush="{StaticResource TextBoxBackgroundBrush}"  VerticalAlignment="Center" DockPanel.Dock="Left"
                            ItemContainerStyle="{StaticResource NoFocusComboBoxItem}"
                            ItemsSource="{Binding Projects}">                            
                            <ComboBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal" HorizontalAlignment="Stretch"/>
                                </ItemsPanelTemplate>
                            </ComboBox.ItemsPanel>
                            
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Border 
                                        Focusable="False"
                                        BorderBrush="{StaticResource TextBoxBorderBrush}" BorderThickness="2" Width="200" Margin="0" Padding="2" >
                                        <StackPanel Orientation="Vertical">
                                            <TextBlock Text="{Binding ClientName}" HorizontalAlignment="Stretch" Style="{StaticResource ItemTitleTextBlock}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" />
                                            <TextBlock Text="{Binding ProjectName}" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"  TextWrapping="NoWrap"  />                                            
                                        </StackPanel>
                                    </Border>                                    
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>

                        <TextBox      
                            x:Name="addTextBox"   VerticalAlignment="Stretch" DockPanel.Dock="Right"
                            
                            ToolTip="{x:Static props:Resources.New_ticket_name}" BorderBrush="{StaticResource TextBoxBackgroundBrush}"
                            Text="{Binding NewTicketName, UpdateSourceTrigger=PropertyChanged}"                                                         
                            HorizontalAlignment="Stretch" >
                            <TextBox.InputBindings>
                                <KeyBinding Key="Enter" Command="{Binding AddJobCommand}"/>
                            </TextBox.InputBindings>
                        </TextBox>

                    </DockPanel>


                </Grid>
            </Grid>
        </SF_Helpers:PanelLayout.Toolbar>

        <SF_Helpers:PanelLayout.Content>
            
            
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0">                        
                        <CheckBox IsChecked="{Binding OnlyMineProjects}" Content="{x:Static props:Resources.only_projects_im_envolved}"/>
                    <TextBlock Text="{Binding Tickets.Count, StringFormat={x:Static props:Resources.N_open_jobs}}" Style="{StaticResource CoverTextTitle}" />
                </StackPanel>

                <Border Grid.Row="1" CornerRadius="5" Padding="5,5,5,0" Background="{StaticResource CoverAreaBrush}">
                    <ListBox                                            
                        ItemContainerStyle="{StaticResource NoHorizontalLineDividedNoSelectionListBoxItem}"                        
                        ItemsSource="{Binding Tickets}"
                        Margin="0,0,10,0">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="150"/>
                                        <ColumnDefinition Width="*"/>                                        
                                    </Grid.ColumnDefinitions>

                                    <Image DataContext="{Binding HasArtifact}" Style="{StaticResource HasArtifactImage}" Grid.ColumnSpan="1" VerticalAlignment="Top" HorizontalAlignment="Right"/>

                                    <!--<Image Grid.Column="0" Style="{StaticResource BacklogItemStatusImage}" DataContext="{Binding Item.Status}" Width="24" Height="24" />-->

                                    <Border Grid.Column="0" Style="{StaticResource TickectBorder}">
                                        <Grid>
                                            <TextBlock Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="{StaticResource BigFontSize}">                                            
                                                <Run Text="#" Foreground="White"/><Run Text="{Binding TrackId, Mode=OneWay}" Foreground="White"/><Run Text="#" Foreground="White"/>
                                            </TextBlock>
                                            <!--<TextBlock 
                                                FontSize="{StaticResource SmallFontSize}" Foreground="White"
                                                Text="{Binding Item.CreateDate, Converter={StaticResource ContextDateConverter}, ConverterParameter=True}" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>-->
                                            <Image DataContext="{Binding Item.IssueType}" Style="{StaticResource IssueImage}" Width="16" Height="16" VerticalAlignment="Top" HorizontalAlignment="Right"/>
                                        </Grid>
                                        <Border.Effect>
                                            <DropShadowEffect ShadowDepth="2" Opacity="0.5"/>
                                        </Border.Effect>
                                    </Border>


                                    <StackPanel Grid.Column="2" Orientation="Vertical" Margin="10,0,0,0" >
                                        <TextBlock>
                                         <Hyperlink                                             
                                            FontSize="{StaticResource BigFontSize}"
                                            Command="{Binding Model.ShowItemCommand, ElementName=thisView}"
                                            CommandParameter="{Binding Item}">
                                             <Run Text="{Binding Item.Name}"/>
                                             </Hyperlink>
                                        </TextBlock>
                                        <TextBlock FontSize="{StaticResource SmallFontSize}" Foreground="Gray" >                                            
                                            <Run Text="{Binding Item.Project.ClientName}"/>
                                            <Run Text=">"/>
                                            <Run Text="{Binding Item.Project.ProjectName}"/>
                                        </TextBlock>

                                        



                                    </StackPanel>

                                    <TextBlock 
                                        Grid.Column="1"
                                        HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"
                                        FontSize="{StaticResource ReallyBigFontSize}" FontWeight="Bold" Foreground="White"
                                        Text="{Binding Item.DeliveryDate, Converter={StaticResource ContextDateConverter}, ConverterParameter=True}" />



                                </Grid>

                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Border>

             


                <TextBox                
                        x:Name="searchTextBox"       
                        Grid.RowSpan="2"
                        Text="{Binding SearchFilterText, UpdateSourceTrigger=PropertyChanged}"                                        
                        Style="{StaticResource SearchTextBox}"/>

                <ContentControl 
                        Grid.ColumnSpan="2"
                            Style="{StaticResource LoadingAnimationContent}"/>

            </Grid>

            
                
            
        </SF_Helpers:PanelLayout.Content>
        
    </SF_Helpers:PanelLayout>
</UserControl>
